<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <script type="text/javascript" src="../../js/commonCss.js"></script>
    <link rel="stylesheet" type="text/css" href="../../styles/common.css" />
    <script type="text/javascript" src="../../js/jquery-1.9.1.min.js"></script>
    <script src="../../js/jquery.formHelp.js"></script>
    <style>
        .form-control[readonly]{
            cursor: auto;
        }
    </style>
</head>
<body>
<form class="definewidth m20" id="subform">
    <p>项目信息：</p>
    <table class="table table-bordered table-hover m10">
        <tr class="hidden">
            <td width="10%" class="tableleft">项目id</td>
            <td><input type="text" name="projectId" id="projectId" value="" placeholder="请输入项目ids"/></td>
        </tr>
        <tr class="hidden">
            <td width="10%" class="tableleft">是否有效</td>
            <td><input type="text" name="isValid" id="isValid" value="true"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">项目编号</td>
            <td style="position: relative;">
                <input type="text" name="projectCode" class="form-control input-sm w300" id="projectCode" maxlength="32"/>
                <div class="required-icon-td">*</div>
            </td>
            <td class="tableleft">原预立编号</td>
            <td><input type="text" name="oldProjectCode" class="form-control input-sm w300" id="oldProjectCode" maxlength="32"/></td>
        </tr>
        <tr>
            <td class="tableleft">项目名称</td>
            <td style="position: relative;"><input type="text" name="projectName" class="form-control input-sm w300" id="projectName" maxlength="100"/><div class="required-icon-td">*</div></td>
            <td class="tableleft">立项日期</td>
            <td><input type="text" name="establishDate" class="form-control input-sm w300" id="establishDate" placeholder="请输入或点击选择日期"/></td>
        </tr>
        <tr>
            <td class="tableleft">项目类型</td>
            <td style="position: relative;">
                <select name="projectType" id="projectType" class="form-control input-sm w300">
                </select>
            </td>
            <td class="tableleft">销售分类</td>
            <td>
                <select name="saleType" id="saleType" class="form-control input-sm w300">
                </select>
            </td>
        </tr>
        <tr>
            <td class="tableleft">销售负责人</td>
            <td style="position: relative;">
                <select name="salerOrganization" id="salerOrganization" class="form-control input-sm w140 dib mr15">
                </select>
                <select name="saler" id="saler" class="form-control input-sm w140 dib mr15">
                </select>
                <div class="required-icon-td">*</div>
            </td>
            <td class="tableleft">项目经理</td>
            <td style="position: relative;">
                <select name="pmOrganization" id="pmOrganization" class="form-control input-sm w140 dib mr15">
                </select>
                <select name="projectManager" id="projectManager" class="form-control input-sm w140 dib">
                </select>
                <div class="required-icon-td">*</div>
            </td>
        </tr>
        <tr>
            <td class="tableleft">项目包</td>
            <td><input type="text" name="projectPackage" id="projectPackage" class="form-control input-sm w300" maxlength="100"/></td>
            <td class="tableleft">关联项目</td>
            <td>
                <select name="relatedProject" id="relatedProject" class="form-control input-sm w300">
                </select>
            </td>
        </tr>
        <tr>
            <td class="tableleft">项目状态</td>
            <td colspan="3">
                <select name="projectStatus" id="projectStatus" class="form-control input-sm w300">
                </select>
            </td>
        </tr>
    </table>
    <p>合同信息：</p>
    <table class="table table-bordered table-hover m10">
        <tr>
            <td class="tableleft">合同编号</td>
            <td><input type="text" name="contractNo" id="contractNo" class="form-control input-sm w300" maxlength="32"/></td>
            <td class="tableleft">合同名称</td>
            <td><input type="text" name="contractName" id="contractName" class="form-control input-sm w300" maxlength="100"/></td>
        </tr>
        <tr>
            <td width="10%" class="tableleft">签订日期</td>
            <td><input type="text" name="singDate" id="singDate" class="form-control input-sm w300" placeholder="请输入或点击选择日期"/></td>
            <td class="tableleft">合同类型</td>
            <td>
                <select name="contractType" id="contractType" class="form-control input-sm w300">
                </select>
            </td>
        </tr>
        <tr>
            <td class="tableleft">服务周期</td>
            <td>
                <div class="form-inline">
                    <input type="text" name="serviceCycle" id="serviceCycle" class="form-control  input-sm w300"   placeholder="4位以下正整数"
                           onkeyup="if(this.value.length>4){this.value=this.value.substr(0,4)};this.value=this.value.replace(/[^\d]/g,'');" onafterpaste="this.value=this.value.replace(/\D/g,'')"/>
                    <span class="input-group">个月</span>
                </div>
            </td>
            <td class="tableleft">维保期</td>
            <td>
                <div class="form-inline">
                    <input type="text" name="maintenancePeriod" id="maintenancePeriod" class="form-control input-sm w300"  placeholder="4位以下正整数"
                           onkeyup="if(this.value.length>4){this.value=this.value.substr(0,4)};this.value=this.value.replace(/[^\d]/g,'');" onafterpaste="this.value=this.value.replace(/\D/g,'')"/>
                    <span class="input-group">个月</span>
                </div>
        </tr>
        <tr>
            <td class="tableleft">客户名称</td>
            <td><input type="text" name="customerName" id="customerName" class="form-control input-sm w300" maxlength="32"/></td>
            <td class="tableleft">地址</td>
            <td><input type="text" name="customerAddress" id="customerAddress" class="form-control input-sm w300" maxlength="100"/></td>
        </tr>
        <tr>
            <td class="tableleft">负责人</td>
            <td><input type="text" name="customerInCharge" id="customerInCharge" class="form-control input-sm w300" maxlength="32"/></td>
            <td class="tableleft">合同状态</td>
            <td>
                <select name="contractStatus" id="contractStatus" class="form-control input-sm w300">
                </select>
            </td>
        </tr>
        <tr>
            <td class="tableleft">产品税率%</td>
            <td><input type="number" name="productRate" id="productRate" class="form-control input-sm w300" placeholder="0.00, 单位：%" value="17" readonly/></td>
            <td class="tableleft">服务税率%</td>
            <td><input type="number" name="serviceRate" id="serviceRate" class="form-control input-sm w300" placeholder="0.00, 单位：%" value="6" readonly/></td>
        </tr>
        <tr>
            <td class="tableleft">产品总金额</td>
            <td><input type="number" name="totalProductAmount" id="totalProductAmount" class="form-control input-sm w300" placeholder="0.00, 单位：元"/></td>
            <td class="tableleft">不含税<br/>产品总金额</td>
            <td><input type="number" name="totalProductNonTax" id="totalProductNonTax" class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="不含税产品总金额=产品总金额/（1+产品税率）" placeholder="0.00, 单位：元" readonly/></td>

        </tr>
        <tr>
            <td class="tableleft">服务总金额</td>
            <td>
                <input type="number" name="totalServiceAmount" id="totalServiceAmount" class="form-control input-sm w300" placeholder="0.00, 单位：元"/>
            </td>
            <td class="tableleft">不含税<br/>服务总金额</td>
            <td><input type="number" name="totalServiceNonTax" id="totalServiceNonTax" class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="不含税服务总金额=服务总金额/（1+服务税率）" placeholder="0.00, 单位：元" readonly/></td>
        </tr>

        <tr>
            <td class="tableleft">合同总金额</td>
            <td><input type="number" name="totalContractAmount" id="totalContractAmount" placeholder="0.00, 单位：元"  class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="合同总金额=产品总金额+服务总金额" readonly/></td>
            <td class="tableleft">不含税<br/>合同总金额</td>
            <td><input type="number" name="totalNonTaxAmount" id="totalNonTaxAmount" class="form-control input-sm w300" placeholder="0.00, 单位：元"  class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="不含税合同总金额=产品总金额/（1+产品税率）+产品总金额/（1+产品税率）" readonly/></td>
        </tr>

        <tr>
            <td class="tableleft">付款条款</td>
            <td colspan="3"><textarea name="paymentProvision" id="paymentProvision" rows="3" class="form-control input-sm w300" style="min-width: 100%" placeholder="请输入250字以内的付款条款" maxlength="250"></textarea></td>
        </tr>
    </table>

<!--    <p>成本及利润：</p>
    <table class="table table-bordered table-hover m10">
        <tr>
            <td class="tableleft">产品采购金额</td>
            <td><input type="number" name="productProAmount" id="productProAmount" class="form-control input-sm w300" placeholder="0.00, 单位：元"/></td>
            <td class="tableleft">不含税<br/>产品采购金额</td>
            <td><input type="number" name="productProNonTax" id="productProNonTax" class="form-control input-sm w300"  placeholder="0.00, 单位：元"  class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="不含税产品采购金额=产品采购金额/（1+产品税率）" readonly/></td>

        </tr>
        <tr>
            <td class="tableleft">服务采购金额</td>
            <td>
                <input type="number" name="serviceProAmount" id="serviceProAmount" class="form-control input-sm w300" placeholder="0.00, 单位：元"/>
            </td>
            <td class="tableleft">不含税<br/>服务采购金额</td>
            <td><input type="number" name="serviceProNonTax" id="serviceProNonTax" class="form-control input-sm w300"  placeholder="0.00, 单位：元"  class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="不含税服务采购金额=服务采购金额/（1+服务税率）" readonly/></td>
        </tr>

        <tr>
            <td class="tableleft">采购总金额</td>
            <td><input type="number" name="totalProAmount" id="totalProAmount" class="form-control input-sm w300"  placeholder="0.00, 单位：元"  class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="采购总金额=产品采购金额+服务采购金额" readonly/></td>
            <td class="tableleft">不含税<br/>采购总金额</td>
            <td><input type="number" name="totalProNonTax" id="totalProNonTax" class="form-control input-sm w300"  placeholder="0.00, 单位：元"  class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="不含税采购总金额=产品采购金额/（1+产品税率）+服务采购金额/（1+服务税率）" readonly/></td>
        </tr>
        <tr>
            <td class="tableleft">实施成本</td>
            <td><input type="number" name="implementationSalary" id="implementationSalary" class="form-control input-sm w300" placeholder="0.00, 单位：元"/></td>
            <td class="tableleft">销售成本</td>
            <td><input type="number" name="salesSalary" id="salesSalary" class="form-control input-sm w300" placeholder="0.00, 单位：元"/></td>
        </tr>
        <tr>
            <td class="tableleft">毛利</td>
            <td><input type="number" name="grossProfit" id="grossProfit" class="form-control input-sm w300"  placeholder="0.00, 单位：元"  class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="毛利=产品总金额/（1+产品税率）+ 产品总金额/（1+产品税率） - 产品采购金额/（1+产品税率） - 服务采购金额 /（1+服务税率） - 实施成本 - 销售成本" readonly/></td>
            <td class="tableleft">利润%</td>
            <td><input type="number" name="profitPercent" id="profitPercent" class="form-control input-sm w300"  placeholder="0.00, 单位：%"  class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="利润% = 毛利 / 合同总金额" readonly/></td>
        </tr>
        <tr>
            <td class="tableleft">管理费用%</td>
            <td>
                <select name="overheadPercent" id="overheadPercent" class="form-control input-sm w300">
                    <option value="5">5.0%</option>
                    <option value="2.5">2.5%</option>
                </select>
            </td>
            <td class="tableleft">管理费用</td>
            <td><input type="number" name="overhead" id="overhead" class="form-control input-sm w300" placeholder="0.00, 单位：元"  class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="管理费用 = 合同总金额 * 管理费用%" readonly/></td>
        </tr>

        <tr>
            <td class="tableleft">销售提成%</td>
            <td><input type="number" name="salesCommissionPercent" id="salesCommissionPercent" class="form-control input-sm w300" placeholder="0.00, 单位：%"/></td>
            <td class="tableleft">销售提成</td>
            <td><input type="number" name="salesCommission" id="salesCommission" class="form-control input-sm w300" placeholder="0.00, 单位：元"  class="form-control input-sm w300" data-toggle="tooltip" data-placement="right" title="销售提成 = 合同总金额 * 销售提成%" readonly/></td>
        </tr>

        <tr>
            <td class="tableleft">利息费用</td>
            <td colspan="3"><input type="number" name="interestExpenses" id="interestExpenses" class="form-control input-sm w300" placeholder="0.00, 单位：元"/></td>
        </tr>
    </table>-->
    <p>验收信息：</p>
    <table class="table table-bordered table-hover m10">
        <tr>
            <td width="10%" class="tableleft">预计初验日期</td>
            <td><input type="text" name="expectedEarlyDate" id="expectedEarlyDate" class="form-control input-sm w300" placeholder="请输入或点击选择日期"/></td>
            <td class="tableleft">实际初验日期</td>
            <td><input type="text" name="actualEarlyDate" id="actualEarlyDate" class="form-control input-sm w300" placeholder="请输入或点击选择日期"/></td>
        </tr>
        <tr>
            <td class="tableleft">预计终验日期</td>
            <td><input type="text" name="expectedFinalDate" id="expectedFinalDate" class="form-control input-sm w300" placeholder="请输入或点击选择日期"/></td>
            <td class="tableleft">实际终验日期</td>
            <td><input type="text" name="actualFinalDate" id="actualFinalDate" class="form-control input-sm w300" placeholder="请输入或点击选择日期"/></td>
        </tr>
        <tr>
            <td class="tableleft">维保结束日期</td>
            <td><input type="text" name="maintenanceEndDate" id="maintenanceEndDate" class="form-control input-sm w300" placeholder="请输入或点击选择日期"/></td>
            <td class="tableleft">预估终验款收到日</td>
            <td><input type="text" name="expectedEarlyCollDate" id="expectedEarlyCollDate" class="form-control input-sm w300" placeholder="请输入或点击选择日期"/></td>
        </tr>
        <tr>
            <td class="tableleft">预计完结日期</td>
            <td><input type="text" name="expectedEndDate" id="expectedEndDate" class="form-control input-sm w300" placeholder="请输入或点击选择日期"/></td>
            <td class="tableleft">实际完结日期</td>
            <td><input type="text" name="actualEndDate" id="actualEndDate" class="form-control input-sm w300" placeholder="请输入或点击选择日期"/></td>
        </tr>
    </table>
    <table class="table table-bordered table-hover m10">
        <tr>
            <td width="10%" class="tableleft">备注</td>
            <td><textarea name="description" id="description" rows="3" class="form-control input-sm w300" style="min-width: 100%" placeholder="请输入120字以内的备注"  maxlength="120"></textarea></td>
        </tr>
    </table>
    <div style="float: right;">
        <button class="btn btn-primary" type="button" id="submitbtn" style="display: none">保存</button>
        <button class="btn btn-primary" type="button" id="updatebtn" style="display: none">保存</button>
        <button class="btn btn-success" type="button" id="backbtn">返回</button>
    </div>
</form>
<script type="text/javascript" src="../../libs/bootstrap-3.3.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="../../libs/bootstrap-datepicker/bootstrap-datepicker.min.css" />
<script type="text/javascript" src="../../libs/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script type="text/javascript" src="../../libs/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.js"></script>
<script type="text/javascript" src="../../js/common.js"></script>
<script type="text/javascript" src="../../js/validateform.js"></script>
<script type="text/javascript" src="../../js/formatTime.js"></script> <!--格式化时间 $.myTime.UnixToDate(unix)-->

<script type="text/javascript">
    //渲染
    $(function () {
        var parentPageId = getQueryString('parentPageId');

        $('[data-toggle="tooltip"]').tooltip()

        $('#backlist').click(function(){
            window.location.href="list.html"
        });
        $('#establishDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#singDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#expectedEarlyDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#actualEarlyDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#expectedFinalDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#actualFinalDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#maintenanceEndDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#expectedEarlyCollDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#expectedEndDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });
        $('#actualEndDate').datepicker({
            language: 'zh-CN',
            format: 'yyyy-mm-dd',
            autoclose:true
        });


        $("#backbtn").click(function () {
            // top.topManager.closePage();
            top.topManager.openPage({
                id : getQueryString('parentPageId'),
                isClose : true
            });
        });

        getParamsByparamTypeValue('projectType', "#projectType");

        getParamsByparamTypeValue('saleType', "#saleType");

        getParamsByparamTypeValue('projectStatus', "#projectStatus");

        //加载部门下拉列表
        $.ajax({
            type: "POST",
            url: ctx + "/organization/getOrganization",
            success: function(data){
                if(data.code == 200){
                    SetdoubleOption('#pmOrganization', '#projectManager', data.data);
                    SetdoubleOption('#salerOrganization', '#saler', data.data);
                    var act = getQueryString('act');
                    if(act == 'add'){
                        $("#submitbtn").show();
                        $("#updatebtn").hide();
                    }else if(act == 'show'){
                        $("#updatebtn").hide();
                        $("#submitbtn").hide();
                        $('.required-icon-td').hide();
                        $('input,select,textarea').attr('disabled','disabled');
                        loadData();
                    }else{
                        $("#submitbtn").hide();
                        $("#updatebtn").show();
                        loadData();
                    }
                }
            }
        });

        $.ajax({
            type: "POST",
            url: ctx + "/user/queryByOraganizationId",
            data:{
                organizationId: 1,
                pageSize: '0'
            },
            success: function(data){
                if(data.code == 200){
                    SetoptionUser('#saler', data.data.rows)
                }
            }
        });

        //关联项目
        $.ajax({
            type: "POST",
            url: ctx + "/project/getAllProjects",
            success: function(data){
                if(data.code == 200){
                    SetProject('#relatedProject', data.data)
                }
            }
        });
        function SetProject(id, param){
            var html = '';
            html +='<option value="">请选择</option>';
            for (var i =0;i<param.length;i++){
                html +='<option value="'+ param[i].projectId +'">'+ param[i].projectName +'</option>';
            }
            $(id).append(html);
        }

        getParamsByparamTypeValue('contractType', "#contractType");
        getParamsByparamTypeValue('contractStatus', "#contractStatus");

        // 提交
        $("#submitbtn").click(function () {
            if($("#subform").valid()){
                var formdata = $("#subform").serializeJson();
                $.ajax({
                    type: 'POST',
                    url: ctx + "/project/add",
                    contentType: "application/json",
                    dataType: 'json',
                    data: JSON.stringify(formdata),
                    success: function(data){
                        if(data.code==200){
                            alert(data.data);
                            top.topManager.openPage({
                                id : parentPageId,
                                isClose : true,
                                reload: true
                            });
                        }else{
                            alert(data.msg);
                        }
                    }
                })
            }
        });

        //更新
        $("#updatebtn").click(function () {
            if($("#subform").valid()){
                var formdata = $("#subform").serializeJson();
                $.ajax({
                    type: 'POST',
                    url: ctx + "/project/update",
                    contentType: "application/json",
                    dataType: 'json',
                    data: JSON.stringify(formdata),
                    success: function(data){
                        if(data.code==200){
                            alert(data.data);
                            top.topManager.openPage({
                                id : parentPageId,
                                isClose : true,
                                reload: true
                            });
                        }else{
                            alert(data.msg);
                        }
                    }
                })
            }
        });


        //计算事件
        $('#productRate,#totalProductAmount').keyup(function(){
            $('#totalProductNonTax').val(($('#totalProductAmount').val()/($('#productRate').val()/100+1)).toFixed(2));
        });

        $('#serviceRate,#totalServiceAmount').keyup(function(){
            $('#totalServiceNonTax').val(($('#totalServiceAmount').val()/($('#serviceRate').val()/100+1)).toFixed(2));
        });
        $('#totalProductAmount,#totalServiceAmount').keyup(function(){
            $('#totalContractAmount').val((Number($('#totalProductAmount').val())+Number($('#totalServiceAmount').val())).toFixed(2));
        });
        $('#productRate,#totalProductAmount,#serviceRate,#totalServiceAmount').keyup(function(){
            $('#totalNonTaxAmount').val((Number($('#totalProductNonTax').val())+Number($('#totalServiceNonTax').val())).toFixed(2));
        });

        /*$('#productProAmount,#productRate').keyup(function () {
            $('#productProNonTax').val(($('#productProAmount').val()/($('#productRate').val()/100+1)).toFixed(2));
        });

        $('#serviceProAmount,#serviceRate').keyup(function(){
            $('#serviceProNonTax').val(($('#serviceProAmount').val()/($('#serviceRate').val()/100+1)).toFixed(2));
        });

        $('#productProAmount,#serviceProAmount').keyup(function(){
            $('#totalProAmount').val((Number($('#productProAmount').val())+Number($('#serviceProAmount').val())).toFixed(2));
        });
        $('#productRate,#productProAmount,#serviceRate,#serviceProAmount').keyup(function(){
            $('#totalProNonTax').val((Number($('#productProNonTax').val())+Number($('#serviceProNonTax').val())).toFixed(2));
        });
        //毛利
        $('#productRate,#totalProductAmount,#serviceRate,#totalServiceAmount,#productProAmount,#serviceProAmount,#implementationSalary,#salesSalary').keyup(function(){
            $('#grossProfit').val((Number($('#totalNonTaxAmount').val())-$('#totalProNonTax').val()-$('#implementationSalary').val()-$('#salesSalary').val()).toFixed(2));
        });
        //利润%
        $('#productRate,#totalProductAmount,#serviceRate,#totalServiceAmount,#productProAmount,#serviceProAmount,#implementationSalary,#salesSalary').keyup(function(){
            $('#profitPercent').val(($('#grossProfit').val()/$('#totalContractAmount').val()*100).toFixed(2));
        });
        //管理费用
        $('#totalProductAmount,#totalServiceAmount,#overheadPercent').keyup(function(){
            $('#overhead').val($('#totalContractAmount').val()*(Number($('#overheadPercent').val()/100)));
        });
        //销售提成
        $('#totalProductAmount,#totalServiceAmount,#salesCommissionPercent').keyup(function(){
            $('#salesCommission').val($('#totalContractAmount').val()*(Number($('#salesCommissionPercent').val()/100)));
        });*/
    });



    function loadData() {
        var id = getQueryString('id');
        $.ajax({
            type: "POST",
            url: ctx + "/project/query",
            data:{
                projectId: id
            },
            success: function(data){
                if(data.code == 200){
                    var backData = data.data.rows[0];
                    backData.establishDate = $.myTime.UnixToDate(backData.establishDate).replace(new RegExp('/',"g"),'-');
                    backData.singDate = $.myTime.UnixToDate(backData.singDate).replace(new RegExp('/',"g"),'-');
                    backData.expectedEarlyDate = $.myTime.UnixToDate(backData.expectedEarlyDate).replace(new RegExp('/',"g"),'-');
                    backData.actualEarlyDate = $.myTime.UnixToDate(backData.actualEarlyDate).replace(new RegExp('/',"g"),'-');
                    backData.expectedFinalDate = $.myTime.UnixToDate(backData.expectedFinalDate).replace(new RegExp('/',"g"),'-');
                    backData.actualFinalDate = $.myTime.UnixToDate(backData.actualFinalDate).replace(new RegExp('/',"g"),'-');
                    backData.maintenanceEndDate = $.myTime.UnixToDate(backData.maintenanceEndDate).replace(new RegExp('/',"g"),'-');
                    backData.expectedEarlyCollDate = $.myTime.UnixToDate(backData.expectedEarlyCollDate).replace(new RegExp('/',"g"),'-');
                    backData.expectedEndDate = $.myTime.UnixToDate(backData.expectedEndDate).replace(new RegExp('/',"g"),'-');
                    backData.actualEndDate = $.myTime.UnixToDate(backData.actualEndDate).replace(new RegExp('/',"g"),'-');

                    var projectManager = backData.projectManager?backData.projectManager:1;
                    var saler = backData.saler?backData.saler:1;


                    $.ajax({
                        type: "POST",
                        url: ctx + "/organization/queryUserOrganization",
                        data:{
                            userId: projectManager
                        },
                        success: function(data){
                            if(data.code == 200){
                                backData.pmOrganization =data.data[0].organizationId;
                                $.ajax({
                                    type: "POST",
                                    url: ctx + "/user/queryByOraganizationId",
                                    data:{
                                        organizationId: backData.pmOrganization,
                                        pageSize: '0'
                                    },
                                    success: function(data){
                                        if(data.code == 200){
                                            SetoptionUser('#projectManager', data.data.rows);
                                            $("#subform").setForm(backData);
                                        }
                                    }
                                })
                            }
                        }
                    });

                    $.ajax({
                        type: "POST",
                        url: ctx + "/organization/queryUserOrganization",
                        data:{
                            userId: saler
                        },
                        success: function(data){
                            if(data.code == 200){
                                backData.salerOrganization =data.data[0].organizationId;
                                $.ajax({
                                    type: "POST",
                                    url: ctx + "/user/queryByOraganizationId",
                                    data:{
                                        organizationId: backData.salerOrganization,
                                        pageSize: '0'
                                    },
                                    success: function(data){
                                        if(data.code == 200){
                                            SetoptionUser('#saler', data.data.rows);
                                            $("#subform").setForm(backData);
                                        }
                                    }
                                })
                            }
                        }
                    });
                } else {
                    alert(data.msg)
                }
            }
        });
    }


    //联动
    function SetdoubleOption(orgElement, userElement, param){
        var html = '';
        html +='<option value="">请选择</option>';
        for (var i =0;i<param.length;i++){
            html +='<option value="'+ param[i].organizationId +'">'+ param[i].orgName +'</option>';
        }
        $(orgElement).append(html);
        var orgid = $(orgElement).val();
        $.ajax({
            type: "POST",
            url: ctx + "/user/queryByOraganizationId",
            data:{
                organizationId: orgid,
                pageSize: '0'
            },
            success: function(data){
                if(data.code == 200){
                    SetoptionUser(userElement, data.data.rows)
                }
            }
        });
        //联动select
        $(orgElement).on("change",function(){
            orgid = $(orgElement).val()
            $.ajax({
                type: "POST",
                url: ctx + "/user/queryByOraganizationId",
                data:{
                    organizationId: orgid,
                    pageSize: '0'
                },
                success: function(data){
                    if(data.code == 200){
                        SetoptionUser(userElement, data.data.rows)
                    }
                }
            })
        });
    }

    function SetoptionUser(id, param){
        $(id).empty();
        var html = '';
        html +='<option value="">请选择</option>';
        for (var i =0;i<param.length;i++){
            html +='<option value="'+ param[i].userId +'">'+ param[i].userName +'</option>';
        }
        $(id).append(html);
    }
</script>
</body>
</html>
